package common

import (
	"fmt"
	"github.com/smartwalle/alipay/v3"
)

// 添加 支付宝沙箱秘钥
// appID
var (
	AppId = "9021000128664144"
	// PrivateKey 私钥
	PrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCNbL9w2cWbkgu1ddhoX4kiGO19OJl7Q7Wph/reRj8eGgIDY/zUTKmkAY6sAerPd5eFLmqcL31jmblCIKHYtv/8BT1+//6HsGfeJLcYitoiEiSbkNmjAB3PP/TMH8TK0ObK3e/J8+sy+MzizLSwxDo1dwdxRqUR5+uusT7NTrMyckzb28AE/L/O1fcOCq5xot1PJtGXdRyJTyP/9PjsQPXuZO+CwvtDojZcyRYy698bS2k8pS5rVt8ORFuM8GfWAqUciL4rGgVwsfd7QEbTU2w+GDLTm0lwLwMN0hNsZpiMcgTjgJMejR/4DX4nlIC7rF2zIB+0HlLmzx3YiiytRTX5AgMBAAECggEAaq6W9yz/eKxBst+zoIA4tQTy2VwBw08/USRnZJa+9BkQXbhmN0uhSDt4gV5s35XKMcfi2fCk+KY0bqKpFA5vqY/WZN/9BCRZJeSyTYwoojznaoZo9iGXWwhWxEhOrePJxUyHnuMmD+xIuelLgHB1rHEepx9wU8KMMdo4kq0EVk9mMvdxBKAt/ugKrFag7jwFAz1vap5m99vHkc2lV4bEBjau8KzzF0Imq/9Voqn6YJbwDp3BoCHUjIN+Q+hp5dr5YSKM1ZfxM/Uh4qVMeJKiljNtvn2ui5tyw9YETU3TTSXTDeLftSbE3A8FkPo/IL70PeW8WtL0PyHGqpYFvv+BJQKBgQDuWhhqNVZ2zM6/tiQlwzTjA+PiI7J3l4XfrHmH7H1pdKlu8tJc2t/Iu+RADlOiCuIc73Nhl2BWVrxM9PO/VTmo2d41hRdIK4yPd5LuPovmRoTryvvLZ5aSqjyybieuC8/eQnu0fQDHDZHDjxXq9F1bH/+RCOD6dE2H3AoL2wxEjwKBgQCX5WviTwJOQMtUy6zxzpEB94aiFoadRNT/rJwwMmRBMYH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AliPay(subject string, outTradeNo string, client *alipay.Client, totalAmount string) string {
	var p = alipay.TradePagePay{}
	p.NotifyURL = ""
	p.ReturnURL = "http://127.0.0.1:8899/return"
	p.Subject = subject
	p.OutTradeNo = outTradeNo
	p.TotalAmount = totalAmount
	p.ProductCode = "FAST_INSTANT_TRADE_PAY"

	var url, err = client.TradePagePay(p)
	if err != nil {
		fmt.Println(err)
		return ""
	}

	// 这个 payURL 即是用于打开支付宝支付页面的 URL，可将输出的内容复制，到浏览器中访问该 URL 即可打开支付页面。
	var payURL = url.String()
	fmt.Println(payURL)
	return payURL
}
